import React, {memo, useEffect,useState} from 'react';
import {shallowEqual, useDispatch, useSelector} from 'react-redux';
import { Table, Tag, Space, Divider, Button, Modal, message,Spin, Form,Input} from 'antd';
import { addAdminInfo } from '../../services/AdminInfo';

const addAdminAction = (adminInfo) => {
    return dispatch => {
        addAdminInfo(adminInfo).then(res => {
            if(res.status == 200)
            {
                message.success(res.message)
            }else{
                message.error(res.message)
            }
        }).catch(err => {
            message.error(err)
        })
    }
}

export default memo(function AddAdminPage(){
    

    const dispatch = useDispatch()
    const onFinish = (values) => {
        console.log(values);
        dispatch(addAdminAction(values));
      };
      const onFinishFailed = (errorInfo) => {
        message.error(errorInfo)
        console.log('Failed:', errorInfo);
      };

    useEffect(()=> {
        console.log("添加管理员!");
    }, [dispatch])

    return (
        <>
            <Divider orientation="left">添加管理员页面</Divider>
            <Form
                name="basic"
                labelCol={{
                span: 8,
                }}
                wrapperCol={{
                span: 16,
                }}
                style={{
                maxWidth: 600,
                }}
                initialValues={{
                remember: true,
                }}
                onFinish={onFinish}
                onFinishFailed={onFinishFailed}
                autoComplete="off"
            >
                <Form.Item
                label="登录手机号"
                name="admin_number"
                rules={[
                    {
                    required: true,
                    message: '请输入手机号',
                    },
                ]}
                >
                <Input />
                </Form.Item>

                <Form.Item
                label="管理员密码"
                name="admin_password"
                rules={[
                    {
                    required: true,
                    message: '请设置管理员密码',
                    },
                ]}
                >
                <Input.Password />
                </Form.Item>
                <Form.Item
                label="管理员姓名"
                name="admin_name"
                rules={[
                    {
                    required: true,
                    message: '请输入管理员姓名',
                    },
                ]}
                >
                <Input />
                </Form.Item>
                <Form.Item
                wrapperCol={{
                    offset: 8,
                    span: 16,
                }}
                >
                <Button type="primary" htmlType="submit">
                    提交
                </Button>
                </Form.Item>
            </Form>
        </>
    )
})